﻿using SwyishChess.Domain.Piece;
using SwyishChess.Utility;

namespace SwyishChess.Domain.Move
{
    public class ChessMove
    {
        /// <summary>
        /// The row location where the chess piece has moved from
        /// </summary>
        public int CurrentRow { get; set; }
        /// <summary>
        /// The column location where the ches piece has moved from
        /// </summary>
        public int CurrentColumn { get; set; }
        /// <summary>
        /// The row location where the chess piece has moved to
        /// </summary>
        public int NewRow { get; set; }
        /// <summary>
        /// The column location where the chess piece has moved to
        /// </summary>
        public int NewColumn { get; set; }
        /// <summary>
        /// The chess piece that has moved
        /// </summary>
        public ChessPiece ChessPiece { get; set; }
        /// <summary>
        /// The owing player of the chess piece
        /// </summary>
        public int OwningPlayerID { get; set; }
        /// <summary>
        /// Keep track of the captured piece if there is any
        /// </summary>
        public ChessPiece CapturedPiece { get; set; }

        /// <summary>
        /// Overloaded constructor
        /// </summary>
        /// <param name="cp"></param>
        /// <param name="currentRow"></param>
        /// <param name="currentColumn"></param>
        /// <param name="newRow"></param>
        /// <param name="newColumn"></param>
        public ChessMove(ChessPiece cp, int currentRow, int currentColumn, int newRow, int newColumn, ChessPiece capturedPiece)
        {
            OwningPlayerID = cp.OwningPlayerId;
            ChessPiece = cp;
            CurrentRow = currentRow;
            CurrentColumn = currentColumn;
            NewRow = newRow;
            NewColumn = newColumn;
            if (capturedPiece != null)
                CapturedPiece = capturedPiece;
        } 

        /// <summary>
        /// Override to string method which gets the details of the chess move
        /// </summary>
        /// <returns>String that represent the cehss move</returns>
        public override string ToString()
        {
            // get player color
            string color = null;
            if (OwningPlayerID == 2)
                color = "Black's ";
            if (OwningPlayerID == 1)
                color = "White's ";

            // get captured piece detail
            string CapturedPieceString = "";
            if (CapturedPiece != null)
            {
                CapturedPieceString = "\n\tCaptured " + CapturedPiece.ToString();
            }

            // create and return the information
            return color + ChessPiece.ToString() + " has moved from " + CoordinateConverter.ConvertColumn(CurrentColumn)
                + CoordinateConverter.ConvertRow(CurrentRow) + " to " + CoordinateConverter.ConvertColumn(NewColumn)
                + CoordinateConverter.ConvertRow(NewRow) + CapturedPieceString;
        }
    }
}
